package io.github.wppli.domain.task.service;

import io.github.wppli.domain.task.model.entity.TaskEntity;
import io.github.wppli.domain.task.repository.ITaskRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: jia-qiang ljq1024.cc
 * @desc: 消息任务服务接口 - 实现
 * @Date: 2024-06-20-21:10
 */
@Service
public class TaskService implements ITaskService {

    @Resource
    private ITaskRepository taskRepository;

    /**
     * 查询发送MQ失败和超时1分钟未发送的MQ
     *
     * @return 未发送的任务消息列表10条
     */
    @Override
    public List<TaskEntity> queryNoSendMessageTaskList() {
        return taskRepository.queryNoSendMessageTaskList();
    }

    /**
     * 发送 Task MQ 任务
     * @param taskEntity 任务实体对象
     */
    @Override
    public void sendMessage(TaskEntity taskEntity) {
        taskRepository.sendMessage(taskEntity);
    }

    /**
     * 发送MQ消息成功
     * @param userId 用户ID
     * @param messageId 消息ID
     */
    @Override
    public void updateTaskSendMessageCompleted(String userId, String messageId) {
        taskRepository.updateTaskSendMessageCompleted(userId, messageId);
    }

    /**
     * 发送MQ消息失败
     * @param userId 用户ID
     * @param messageId 消息ID
     */
    @Override
    public void updateTaskSendMessageFail(String userId, String messageId) {
        taskRepository.updateTaskSendMessageFail(userId, messageId);
    }
}
